<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>系统设置</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="{{URL::asset('layui/css/layui.css')}}"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<fieldset class="layui-elem-field" style="margin-top: 20px;">
    <legend>积分系统状态设置</legend>

    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">积分系统</label>
            <div class="layui-input-block">
                <input type="checkbox" @if($sys['open']=='true') checked="" @endif name="open" lay-skin="switch" lay-filter="switchTest" lay-text="打开|关闭">
            </div>
        </div>
    </form>
</fieldset>

<fieldset class="layui-elem-field" style="margin-top: 20px;">
    <legend>其他设置</legend>

    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">单价/积分兑换比例</label>
            <div class="layui-input-inline">
                <input type="text" name="score_ratio" autocomplete="off" value="{{$sys['score_ratio']}}" placeholder="单价/积分兑换比例" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户充值销售回扣积分</label>
            <div class="layui-input-inline">
                <input type="text" name="sell_ratio"  autocomplete="off" value="{{$sys['sell_ratio']}}" placeholder="单价/积分兑换比例" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邀请充值赠送积分</label>
            <div class="layui-input-inline">
                <input type="text" name="invit_ratio" autocomplete="off" value="{{$sys['invit_ratio']}}" placeholder="单价/积分兑换比例" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">保存</button>
            </div>
        </div>
    </form>
</fieldset>



<script src="{{URL::asset('layui/layui.js')}}" charset="utf-8"></script>
<script src="{{URL::asset('js/jquery-3.1.1.min.js')}}" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use('form', function(){
        var form = layui.form
            ,layer = layui.layer;

        //监听指定开关
        form.on('switch(switchTest)', function(data){
            var open = this.checked ? 'true' : 'false';
            $.post('/admin/system/api/open',{"open":open},function (d) {
                layer.tips('状态:'+open, data.othis)
            });
            //layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });

        //监听提交
        form.on('submit(demo1)', function(data){
            var score_ratio = data.field.score_ratio;
            var sell_ratio = data.field.sell_ratio;
            var invit_ratio = data.field.invit_ratio;
            $.post('/admin/system/api/other',{"score_ratio":score_ratio,"sell_ratio":sell_ratio,"invit_ratio":invit_ratio},function (d) {
                if (d.code==200){
                    layer.msg("设置成功");
                    setTimeout(function () {
                        window.location.reload();
                    },500)
                } else {
                    layer.msg("设置失败");
                }
            });
            return false;
        });


    });
</script>

</body>
</html>